import { readFile } from "node:fs/promises"; import { join } from "node:path"; import { ImageResponse } from "next/og"; import type { NextRequest } from "next/server"; import { getPageImage, source } from "@/lib/geistdocs/source"; export const GET = async ( _request: NextRequest, { params }: RouteContext<"/[lang]/og/[...slug]"> ) => { const { slug, lang } = await params; const page = source.getPage(slug.slice(0, -1), lang); if (!page) { return new Response("Not found", { status: 404 }); } const { title, description } = page.data; const regularFont = await readFile( join(process.cwd(), "app/[lang]/og/[...slug]/geist-sans-regular.ttf") ); const semiboldFont = await readFile( join(process.cwd(), "app/[lang]/og/[...slug]/geist-sans-semibold.ttf") ); const backgroundImage = await readFile( join(process.cwd(), "app/[lang]/og/[...slug]/background.png") ); const backgroundImageData = backgroundImage.buffer.slice( backgroundImage.byteOffset, backgroundImage.byteOffset + backgroundImage.byteLength ); return new ImageResponse(